def find_patrick(path: str, threshold: float=0.009)->bool:
    """
    path: 文件路径
    threshold: 派大星存在判断阈值
    在图片中找派大星，找到返回 True 没找到返回 False
    """
    from PIL import Image
    red, green, blue = 200, 105, 115    # 派大星主色颜色值
    mistake = 10    # 色域允许的误差范围

    img = Image.open(path)  # 打开图像文件
    colors = img.getcolors(img.size[0] * img.size[1])   # 按像素把所有颜色打平为数组

    count = 0   # 包含相关颜色判定像素
    pixel_count = len(colors)   # 图像像素总量
    for color in colors:
        r, g, b = color[1][0], color[1][1], color[1][2]
        if int(r) in range(red-mistake, red+mistake+1) and int(g) in range(green-mistake, green+mistake+1) and int(b) in range(blue-mistake, blue+mistake+1):
            count += 1
    return True if count/pixel_count >= threshold else False

def del_noused_file() -> None:
    """
    删除无用文件，只保留包含派大星的
    """
    import os
    files_name = os.listdir('./images')
    images_name = list()
    for file in files_name:
        if '.jpeg' in file:
            images_name.append(file)
    images_name.sort(key=lambda x: int(x.split('.')[0]))
    for file_name in files_name:
        has_patrick = find_patrick('./images/'+file_name)
        if not has_patrick:
            os.remove('./images/'+file_name)
    print('>>> Step.2 未包含派大星的图片已被清除.')
del_noused_file()